import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Register from '../views/Register.vue'
import Login from '../views/Login.vue'
import Usermanage from '../views/Usermanage/Usermanage.vue'
import Userdetails from '../views/Usermanage/Userdetails.vue'
import Userlist from '../views/Usermanage/Userlist.vue'
import blacklist from '../views/Usermanage/blacklist.vue'
import banIplist from '../views/Usermanage/banIplist.vue'
import Public from '../views/Public/Public.vue'
import Publiclist from '../views/Public/Publiclist.vue'
import Publicdetails from '../views/Public/Publicdetails.vue'
import Pablicsetting from '../views/Public/Pablicsetting.vue'
import Autoreply from '../views/Public/Autoreply.vue'
import Newzeng from '../views/Public/Newzeng.vue'
import Publicadd from '../views/Public/Publicadd.vue'
import Price from '../views/Price/Price.vue'
import Income from '../views/Income/Income.vue'
import Custom from '../views/Price/Custom/Custom.vue'
import Agency from '../views/Price/Agency/Agency.vue'
import Drainage from '../views/Price/Drainage/Drainage.vue'
import Team from '../views/Price/Team/Team.vue'
import Earnings from '../views/Income/Earnings/Earnings.vue'
import Record from '../views/Income/Record/Record.vue'
import Usercontent from '../views/Home/Usercontent.vue'
import Homecontent from '../views/Home/Homecontent.vue'

import cookie from 'vue-cookie'

Vue.use(VueRouter)	

const routes = [
  {
    path: '/',
    redirect:'/login'
  },
  {
    path: '/Login',
    name: 'Login',
    component: Login
  },
  {
    path: '/Register',
    name: 'Register',
    component: Register
  },
  {
    path: '/Home',
    name: 'Home',
    component: Home,
    children:[
      {   
          name:'Homecontent',
          path:'/Homecontent',
          component:Homecontent
      },
      {   
        name:'Usercontent',
        path:'/Usercontent',
        component:Usercontent
      },
      {
        path:'/Usermanage',
        component:Usermanage,
        redirect:'/Usermanage/Userlist',
        children:[
          {name: 'Userlist',path:'/Usermanage/Userlist',component:Userlist},
          {name: 'Userdetails',path:'/Usermanage/Userdetails',component:Userdetails},
          {name: 'blacklist',path:'/Usermanage/blacklist',component:blacklist},
          {name: 'banIplist',path:'/Usermanage/banIplist',component:banIplist}
        ]
      },
      {
        path:'/Public',
        component:Public,
        redirect: '/Public/Publiclist',
        children:[
          {name:'Publiclist',path:'/Public/Publiclist',component:Publiclist},
          {name:'Publicdetails',path:'/Public/Publicdetails',component:Publicdetails},
          {name:'Autoreply',path:'/Public/Autoreply',component:Autoreply},
          {name:'Newzeng',path:'/Public/Newzeng',component:Newzeng},
          {name:'Publicadd',path:'/Public/Publicadd',component:Publicadd},
          {name:'Pablicsetting',path:'/Public/Pablicsetting',component:Pablicsetting}
        ]
      },
      {path:'/Price',component:Price,
        children:[
          {path:'/Price/Custom',component:Custom},
          {path:'/Price/Drainage',component:Drainage},
          {path:'/Price/Agency',component:Agency},
          {path:'/Price/Team',component:Team}
        ]
      },
      {path:'/Income',component:Income,
        children:[
          {path:'/Income/Earnings',component:Earnings},
          {path:'/Income/Record',component:Record}
        ]
      }
    ]
  }
]

const router = new VueRouter({
  routes
})


//挂载路由导航守卫
router.beforeEach((to,from,next)=>{
  if(to.path==='/Login' || to.path==='/Register') return next();
  //获取token
  const tokenStr = cookie.get('token')
  if(!tokenStr) return next('/Login');
  next();
})

export default router
